def matches(dev, mode) :
    import re
    return (
        re.search("Logitech_Cordless_RumblePad_2", dev)
            and
        mode == "fly"
    )

def handler(self, event) :
    import osg
    if event["mode"] == "analog" :
        # gets stuck on small values when not pressed
        for i in range( len(event["data"]) ) :
            if abs(event["data"][i]) < 0.3 :
                event["data"][i] = 0.0
            #sign = (event["data"][i] > 0) * 2 - 1
            event["data"][i] **= 3
        self.velocity = osg.Matrixd()
        self.velocity.postMult(
            osg.Matrixd.translate(
                 event["data"][0] * self.nav_scale["translation"][0] * 0.3,
                -event["data"][5] * self.nav_scale["translation"][1] * 0.3,
                 event["data"][1] * self.nav_scale["translation"][2] * 0.3,
            )
        )
        self.velocity.postMult(
            osg.Matrixd.rotate(
                event["data"][2] * self.nav_scale["rotation"], 0, -1, 0
            )
        )
        self.velocity.postMult(
            osg.Matrixd.rotate(
                event["data"][3] * self.nav_scale["rotation"], -1, 0, 0
            )
        )
    elif event["mode"] == "button" and event["data"] == [ 6, "pressed" ] :
        self.button_velocity.postMult(
            osg.Matrixd.rotate(
                self.nav_scale["rotation"], 0, 0, -1
            )
        )
    elif event["mode"] == "button" and event["data"] == [ 6, "released" ] :
        self.button_velocity = osg.Matrixd()
    elif event["mode"] == "button" and event["data"] == [ 7, "pressed" ] :
        self.button_velocity.postMult(
            osg.Matrixd.rotate(
                self.nav_scale["rotation"], 0, 0, 1
            )
        )
    elif event["mode"] == "button" and event["data"] == [ 7, "released" ] :
        self.button_velocity = osg.Matrixd()
    elif event["mode"] == "button" and event["data"][0] == 9 :
        self.velocity = osg.Matrixd()
        self.button_velocity = osg.Matrixd()

